package com.ymttest.business.service.productdata.service;

import java.io.File;
import java.util.List;

import org.json.JSONObject;

import com.ymatou.iapi.productquery.service.GetProductInfoByProductIdCall;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.utils.FileUtil;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.compare.AssertHelper;
import com.ymttest.utils.compare.LogPathConf;
import com.ymttest.utils.compare.LoggerHelper;
import com.ymttest.utils.compare.LoggerInterface;

public class SetOffProduct {
	public static void main(String args[]){
		LogPathConf logPathConf = new LogPathConf(false);
		LoggerInterface logger = new LoggerHelper(logPathConf);
		AssertHelper.setLoggerInterface(logger);
		
		
		String userIdAndName = System.getProperty("user.dir") + File.separator + "resource" + File.separator
				+"CompareData"+File.separator+"productId.txt"; 
		
		List<String> productIds = FileUtil.readFileAsLine(userIdAndName);
		
		
		for(int i=0;i<productIds.size();i++){
			String productId = productIds.get(i);
			System.out.println("productId:"+productId);
			JSONObject prodDetail = new GetProductInfoByProductIdCall().callAndGetReturnData(productId);
			try {
				if (!prodDetail.isNull("Data")&&!prodDetail.getJSONObject("Data").isNull("Product")){
					int sellerId = prodDetail.getJSONObject("Data").getJSONObject("Product").getInt("SellerId");
					JSONObject ret=SellerProductCallService.batchSetProductOffSale(productId,sellerId);
					if (!ret.isNull("Code") && (ret.getInt("Code")==200)){
						logger.verifyEquals(true, true, "productId:"+productId+", set off");
					}else{
						logger.verifyEquals(true, true, "productId:"+productId+", is not set off");
					}
					
				}else{
					logger.failure( "ProductId:"+productId+", is not set off");
				}
			} catch (Exception e) {
				logger.failure("ProductId:"+productId, e);
			}
			YMTDateUtil.waitTime(0.05);
		}
		
	}
}
